<template>
  <el-form-item :rules="item.rule" :label="item.label" :prop="item.prop">
    <div class="mix el-input el-input-group el-input--suffix">
      <div class="el-input-group__prepend" v-if="item.prepend">
        {{ item.prepend }}
      </div>
      <div class="inputWarpper">
        <div class="valueRange">
          <el-input-number
            v-model="formData[item.prop][0]"
            :controls="false"
            @change="changer"
            :disabled="item.disabled"
            :max="item.max"
            :min="item.min"
            :precision="item.precision === undefined ? 0 : item.precision"
            :placeholder="
              item.startPlaceholder === undefined
                ? '请输入'
                : item.startPlaceholder
            "
          >
          </el-input-number>
        </div>
        <div class="valueRange">
          -
        </div>
        <div class="valueRange">
          <el-input-number
            v-model="formData[item.prop][1]"
            :controls="false"
            @change="changer"
            :disabled="item.disabled"
            :max="item.max"
            :min="item.min"
            :precision="item.precision === undefined ? 0 : item.precision"
            :placeholder="
              item.endPlaceholder === undefined ? '请输入' : item.endPlaceholder
            "
          >
          </el-input-number>
        </div>
      </div>
      <div class="el-input-group__append" v-if="item.append">
        {{ item.append }}
      </div>
    </div>
  </el-form-item>
</template>

<script>
export default {
  name: "inputNumberRangeCom",
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      }
    },
    formData: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  methods: {
    changer() {
      if (this.item.change) {
        this.item.change(
          this.formData[this.item.prop][0],
          this.formData[this.item.prop][1]
        );
      }
    }
  }
};
</script>

<style scoped lang="scss">
.mix {
  display: inline-flex;
}
.inputWarpper {
  border: 1px solid #dcdfe6;
  display: flex;
  width: 100%;
}
.mix .valueRange:nth-child(1) {
  padding-right: 0 !important;
}

.mix .valueRange:nth-child(2) {
  padding-left: 0 !important;
  padding-right: 0 !important;
  color: rgb(140, 147, 157) !important;
  padding: 5px 0 !important;
}

.mix .valueRange:nth-child(3) {
  padding-left: 0 !important;
}
::v-deep .el-input__inner {
  border: none !important;
}
::v-deep.el-input-group__prepend,
::v-deep.el-input-group__append {
  padding: 5px 20px;
  text-indent: -7px;
}
::v-deep.el-form-item.is-error .mix .inputWarpper {
  border-color: #f56c6c;
}
</style>
